package com.weimob.xh;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.Test;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.*;

/**
 * @program: xh-learn-record
 * @description:
 * @author: sch
 * @create: 2022-12-01 20:57
 **/
@RestController
@RequestMapping("test")
public class TestDemo {
    @Test
    public void test() {
        System.out.println("test");
    }

    @RequestMapping("hello")
    public String testSpringboot() {
        return "hello world";
    }

    @Test
    public void test2() throws JMSException {
        System.out.println(ActiveMQConnectionFactory.DEFAULT_USER + ","
                + ActiveMQConnectionFactory.DEFAULT_PASSWORD + ","
                + ActiveMQConnectionFactory.DEFAULT_BROKER_URL);

        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_USER,
                ActiveMQConnectionFactory.DEFAULT_PASSWORD, "tcp://localhost:61617");
        System.out.println(connectionFactory);

        Connection connection = connectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);
        Destination queue1 = session.createQueue("queue1");
        MessageProducer producer = session.createProducer(queue1);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

        TextMessage textMessage = session.createTextMessage();
        textMessage.setText("queue1-test01");
        producer.send(textMessage);

//        session.commit();
//        connection.close();
    }
}
